package com.furschina.struts2.portal;

import java.util.Collection;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts2.convention.annotation.InterceptorRef;
import org.apache.struts2.convention.annotation.InterceptorRefs;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.stereotype.Controller;

import cn.wooshai.core.struts2.PaginationAware;
import cn.wooshai.core.struts2.WooshaiAction;
import cn.wooshai.core.vo.PageModel;

import com.furschina.Constants;
import com.furschina.model.Topic;
import com.furschina.service.TopicService;
import com.furschina.struts2.BaseAction;
import com.furschina.vo.TopicPage;

/**
 * @author iday
 * 
 */
@Controller("protal/topic")
@InterceptorRefs({ @InterceptorRef(Constants.DEFAULT_STACK_REF),
		@InterceptorRef(Constants.VALIDATOR_REF) })
@Result(name = WooshaiAction.SUCCESS, type = "redirect", location = "home.xhtml")
public class TopicAction extends BaseAction implements PaginationAware {

	/**
	 * 
	 */
	private static final long serialVersionUID = 5208755693142060681L;

	static Log LOG = LogFactory.getLog(TopicAction.class);

	private Topic topic;

	private Collection<Topic> list;

	private TopicPage pm;

	private String id;

	private TopicService topicService;

	/*
	 * ==========setter and getter===========
	 */
	public void setTopic(Topic topic) {
		this.topic = topic;
	}

	public Topic getTopic() {
		return topic;
	}

	/**
	 * @param list
	 *            the list to set
	 */
	public void setList(Collection<Topic> list) {
		this.list = list;
	}

	/**
	 * @return the list
	 */
	public Collection<Topic> getList() {
		return list;
	}

	@Override
	public PageModel getPm() {
		return pm;
	}

	@Override
	public void setPage(int page) {
		this.pm.setPage(page);
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getId() {
		return id;
	}

	public void setTopicService(TopicService topicService) {
		this.topicService = topicService;
	}

	public TopicService getTopicService() {
		return topicService;
	}

	/*
	 * ================Method===============
	 */

	public String index() {
		list = topicService.queryAll(pm);
		return INDEX;
	}

	public String show() {
		this.topic = this.topicService.findByPrimaryKey(id);
		return SHOW;
	}

	public String create() {
		this.topicService.create(topic);
		return SUCCESS;
	}

	public String update() {
		this.topicService.update(topic);
		return SUCCESS;
	}

	public String include() {
		this.list = topicService.queryAll(pm);
		return null;
	}

}
